export default {
    name: 'UTableBody',
    props: {
        store: {},
    },
    data() {
        return {
        };
    },
    computed: {
        table() {
            return this.$parent;
        },
    
        data() {
            // table.vue watch.data 中 调用 setData 在store 中存储 data
            return this.store.states.data;
        },
        columns() {
            return this.store.states.columns;
        },
    },
    render(createElement) {
        return (
            <tbody>
                { this._l(this.data, (row, $index) =>
                    [<tr key={$index} on-click={ ($event) => this.handleClick($event, row) }>
                        { this._l(this.columns, (column, cellIndex) => {
                            return (<td class={column.className}>
                                { column.renderCell.call(
                                    this._renderProxy,
                                    createElement,
                                    {
                                        row,
                                        column,
                                        $index,
                                        store: this.store,
                                    },
                                )}
                            </td>)
                        })}
                    </tr>]
                )}
            </tbody>
        );
    },
    methods: {
        handleClick(event, row) {
            this.table.$emit(`row-click`, row , event);
        },
    },
}